mui.init({
    pullRefresh: {
        container: "#refreshContainer", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
        down: {
            style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
            color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
            height: '50px', //可选,默认50px.下拉刷新控件的高度,
            range: '100px', //可选 默认100px,控件可下拉拖拽的范围
            offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
            auto: false, //可选,默认false.首次加载自动上拉刷新一次
            callback: function () {
                qdetails.getUserQuestionData();
                setTimeout(function () {
                    mui('#refreshContainer').pullRefresh().endPulldownToRefresh(false);
                },1000)
            }
        }
    }
});

var qdetails;
mui.plusReady(function () {
	//禁用ios右滑返回
    plus.webview.currentWebview().setStyle({ 'popGesture': 'none' });
	hideScrollBar();
    qdetails = new Vue({
        el: '#data_box',
        data: {
            keguan_lists: [],
            zhuguan_lists: [],
            orther: [],
            isShow1: true,
            isShow2: true,
            loginSta:0,
        },
        mounted() {
            this.getUserQuestionData();
            this.updateStatus();
        },
        methods: {
            getUserQuestionData: function () {
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/questionbank/category/getKnowledgeCategoryList',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if(msg.code == 1){
                            qdetails.keguan_lists = msg.data.keguan;
                            qdetails.zhuguan_lists = msg.data.zhuguan;
                            qdetails.orther = msg.data.other_data;
                        }else{
                            mui.toast(msg.msg, {duration: '200',type: 'div'});
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('加载失败!', {duration: '200',type: 'div'});
                    },
                    complete: function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            updateStatus:function(){
                var api_host = plus.storage.getItem('HOST_URL');
                var self = this;
                mui.ajax({
                    url: api_host + '/api/linxuan/user/checkLoginStatus',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            self.loginSta = 1;
                        } else {
                            self.loginSta = 0;
                            console.log(msg.msg);
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('登录状态请求失败请重试', {duration: '300'});
                    }
                });
            },
            //显示隐藏二级内容
            toggle1: function () {
                $('.toggle1').slideToggle(200);
            },
            toggle2: function () {
                $('.toggle2').slideToggle(200);
            },
            open_brushing_kg: function (catid) {
                // 打开客观题刷题界面
                if(this.loginSta == 0){
                    mui.toast('该功能需要登录后使用', {duration: '300'});
                }else{
                    mui.openWindow({
                        url: '../tiku/exercises.html',
                        createNew: false,
                        extras: {
                            'catid': catid
                        },
                        show: {
                            autoShow: true,
                            aniShow: 'pop-in',
                            duration: 400
                        },
                        waiting: {
                            autoShow: false,
                        }
                    });
                }
            },
            open_brushing_zg: function (catid) {
                if(this.loginSta == 0){
                    mui.toast('该功能需要登录后使用', {duration: '300'});
                }else{
                    // 打开主观题刷题界面
                    mui.openWindow({
                        url: '../tiku/shortAnswer.html',
                        createNew: false,
                        show: {
                            autoShow: true,
                            aniShow: 'pop-in',
                            duration: 400
                        },
                        waiting: {
                            autoShow: false,
                        },
                        extras: {
                            'catid': catid
                        },
                    });
                }

            },
            open_taoti: function () {
                //打开套题页面
                mui.openWindow({
                    url: '../tiku/exercisesTaoti.html',
                    createNew: false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            open_lishi: function () {
                if(this.loginSta == 0){
                    mui.toast('该功能需要登录后使用', {duration: '300'});
                }else{
                    //打开练习历史
                    mui.openWindow({
                        url: '../tiku/exercisesHistory.html',
                        createNew: false,
                        show: {
                            autoShow: true,
                            aniShow: 'pop-in',
                            duration: 400
                        },
                        waiting: {
                            autoShow: false,
                        }
                    })
                }
            },
            open_cuoti: function () {
                if(this.loginSta == 0){
                    mui.toast('该功能需要登录后使用', {duration: '300'});
                }else{
                    //打开错题收藏
                    mui.openWindow({
                        url: '../tiku/wrongCollection.html',
                        createNew: false,
                        show: {
                            autoShow: true,
                            aniShow: 'pop-in',
                            duration: 400
                        },
                        waiting: {
                            autoShow: false,
                        }
                    })
                }

            },
            open_notes: function () {
                if(this.loginSta == 0){
                    mui.toast('该功能需要登录后使用', {duration: '300'});
                }else{
                    //打开习题笔记
                    mui.openWindow({
                        url: '../tiku/exercisesNote.html',
                        createNew: false,
                        show: {
                            autoShow: true,
                            aniShow: 'pop-in',
                            duration: 400
                        },
                        waiting: {
                            autoShow: false,
                        }
                    })
                }

            }
        }
    })
})

document.addEventListener("refreshData", function () {
    var embed = plus.webview.currentWebview();
    embed.reload(true);
});
